{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "\"\"\"To test the implementation of gcloud.py\"\"\"\n",
    "from syft.grid.autoscale import gcloud\n",
    "from syft.grid.autoscale.utils import gcloud_configurations as configs"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "NEW = gcloud.GoogleCloud(\n",
    "    credentials=\"/usr/terraform.json\", project_id=\"project\", region=\"us-central1\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# create a grid network instance and then add nodes to it one by one\n",
    "NEW.create_gridnetwork(\n",
    "    name=\"new-network\", machine_type=configs.MachineType.f1_micro, zone=configs.Zone.us_central1_a,\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# add node to created grid network\n",
    "NEW.create_gridnode(\n",
    "    name=\"new-node\",\n",
    "    machine_type=configs.MachineType.f1_micro,\n",
    "    zone=configs.Zone.us_central1_a,\n",
    "    gridnetwork_name=\"new-network\",\n",
    ")\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "NEW.destroy()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# to create a cluster we first need to reserve an external ip\n",
    "NEW.reserve_ip(\"grid\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# pass the name of the reserved ip to the cluster\n",
    "c1 = NEW.create_cluster(\n",
    "    name=\"new-12345\",\n",
    "    machine_type=configs.MachineType.f1_micro,\n",
    "    zone=configs.Zone.us_central1_a,\n",
    "    reserve_ip_name=\"grid\",\n",
    "    target_size=3,\n",
    "    eviction_policy=\"delete\",\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "c1.sweep()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "NEW.destroy()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.7.6 64-bit ('syft': conda)",
   "language": "python",
   "name": "python37664bitsyftconda3821869f2cbc432c8ddeb2e882487673"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}